using System;

namespace Drill.Core.Builders
{
	public class DependencyResolverBuilderDirector : IDependencyResolverBuilderDirector
	{
		private IDependencyResolverBuilder _builder;

		public void Initialize(IDependencyResolverBuilder builder)
		{
			if (null == builder)
			{
				throw new ArgumentNullException("builder");
			}
			_builder = builder;
		}

		public IDependencyResolver Build()
		{
			// The order of operations is very important in this method.
			_builder.BuildRootPathProviders();
			_builder.BuildSearchPaths();
			_builder.BuildConfigurationHelper();
			_builder.BuildDrillBits();
			_builder.BuildInitializationContext();
			_builder.CreateDependencyResolver();
			return _builder.GetDependencyResolver();
		}
	}
}